﻿//TODO: Rename in accordance with the view name when its done properly.
Hoot.Views.Folder = {
    
    init: function () {
        var options = { parentId: 0, success: Hoot.Views.Folder.getFolders_SuccessHandler };
        Hoot.Api.Folders.getFolders(options);

        $('#btnAdd').click(Hoot.Views.Folder.addFolder);
    },

    getFolders_SuccessHandler : function (folders) {
        $('#divFolderList').empty();
        $('#folderTemplate').tmpl(folders).appendTo("#divFolderList");    
    },
     
    addFolder : function() {
        var name = prompt('Folder Name');
        var options = { folder: { Name: name, ParentFolderId: null, Description: "" }, success: Hoot.Views.Folder.addFolders_SuccessHandler }
        Hoot.Api.Folders.addFolder(options);
    },

    addFolders_SuccessHandler : function(folder) {
        $('#folderTemplate').tmpl(folder).appendTo("#divFolderList");   
    },
};

$(document).ready(Hoot.Views.Folder.init);